package oo;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import javax.faces.context.FacesContext;
import javax.faces.event.AbortProcessingException;
import javax.faces.event.ValueChangeEvent;
import javax.faces.model.SelectItem;
 
public class CountryBean implements Serializable{
	
	private static final long serialVersionUID = 1L;
	
	public CountryBean() {
		super();
		pozycje=new ArrayList<SelectItem>();
		pozycje.add(new SelectItem("jeden"));
		pozycje.add(new SelectItem("dwa"));
		
	}

	public List<SelectItem> getPozycje() {
		return pozycje;
	}

	public void setPozycje(List<SelectItem> pozycje) {
		this.pozycje = pozycje;
	}

	private static Map<String,String> countries;
	private List<SelectItem> pozycje;
	
	private String localeCode;// = "en"; //default value 
	public void zmiana(ValueChangeEvent event)
			{//throws AbortProcessingException {
		System.out.println("cc"+event.getNewValue());
		//access country bean directly
		/*CountryBean country = (CountryBean) FacesContext.getCurrentInstance().
			getExternalContext().getSessionMap().get("country");

		country.setLocaleCode(event.getNewValue().toString());*/
		
	}
	static{
		countries = new LinkedHashMap<String,String>();
		countries.put("United Kingdom", "en"); //label, value
		countries.put("French", "fr");
		countries.put("German", "de");
		countries.put("China", "zh_CN");
	}

	public void countryLocaleCodeChanged(ValueChangeEvent e){
		//assign new value to localeCode
		localeCode = e.getNewValue().toString();
		
	}

	public Map<String,String> getCountryInMap() {
		return this.countries;
	}

	public String getLocaleCode() {
		return localeCode;
	}

	public void setLocaleCode(String localeCode) {
		this.localeCode = localeCode;
	}

}
